import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        xxx: 'cro',
        num: 5
    },
    getters: {
        z(a) {
            return a.num + '刀乐'
        }
    },
    mutations: {
        add(state, value) {
            console.log(state);
            console.log(value);
            state.num += value[0]
            if (state.xxx.length < 4) {
                state.xxx += value[1]
            }
        },
        addd(state) {
            state.num += 1
        },
        sub(state) {
            if (state.num < 1) {
                alert('不能再小了')
            } else {
                state.num -= 1
            }

        }
    },
    actions: {
        add(context, value) {
            console.log(context);
            console.log(value);
            context.commit('add', value)
        },
        addd(context) {
            context.commit('addd')
        },
        sub(context) {
            context.commit('sub')
        }
    },
    modules: {}
})